package com.tianluo.tianluobookstore.task;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
public class OrderDelayItem implements Delayed {

    private final String orderId;
    private final long expireTime;

    public OrderDelayItem(String orderId, long delayMillis) {
        this.orderId = orderId;
        this.expireTime = System.currentTimeMillis() + delayMillis;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(expireTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return Long.compare(this.expireTime, ((OrderDelayItem) o).expireTime);
    }

    public String getOrderId() {
        return orderId;
    }
}
